home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 13 / CU Amiga Magazine's Super CD-ROM 13 (1997)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1997-08].iso / CUCD / Graphics / Ghostscript / data / gs_init.ps < prev    next >
Text File  |  1997-04-12  |  42KB  |  1,366 lines

  1. %    Copyright (C) 1989, 1996 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % Initialization file for the interpreter.
  16. % When this is run, systemdict is still writable.
  17.  
  18. % Comment lines of the form
  19. %    %% Replace <n> <file(s)>
  20. % indicate places where the next <n> lines should be replaced by
  21. % the contents of <file(s)>, when creating a single merged init file.
  22.  
  23. % The interpreter can call out to PostScript code.  All procedures
  24. % called in this way, and no other procedures defined in these
  25. % initialization files, have names that begin with %, e.g.,
  26. % (%Type1BuildChar) cvn.
  27.  
  28. % Check the interpreter revision.  NOTE: the interpreter code requires
  29. % that the first non-comment token in this file be an integer.
  30. 403
  31. dup revision ne
  32.  { (gs: Interpreter revision \() print revision 10 string cvs print
  33.    (\) does not match gs_init.ps revision \() print 10 string cvs print
  34.    (\).\n) print flush null 1 .quit
  35.  }
  36. if pop
  37.  
  38. % Acquire userdict, and set its length if necessary.
  39. /userdict where
  40.  { pop userdict maxlength 0 eq }
  41.  { true }
  42. ifelse
  43.  {        % userdict wasn't already set up by iinit.c.
  44.    /userdict
  45.    currentdict dup 200 .setmaxlength        % userdict
  46.    systemdict begin def        % can't use 'put', userdict is local
  47.  }
  48.  { systemdict begin
  49.  }
  50. ifelse
  51.  
  52. % Define dummy local/global operators if needed.
  53. systemdict /.setglobal known
  54.  { true .setglobal
  55.  }
  56.  { /.setglobal { pop } bind def
  57.    /.currentglobal { false } bind def
  58.    /.gcheck { pop false } bind def
  59.  }
  60. ifelse
  61.  
  62. % Define .languagelevel if needed.
  63. systemdict /.languagelevel known not { /.languagelevel 1 def } if
  64.  
  65. % Optionally choose a default paper size other than U.S. letter.
  66. % (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
  67.  
  68. % Turn on array packing for the rest of initialization.
  69. true setpacking
  70.  
  71. % Define the old MS-DOS EOF character as a no-op.
  72. % This is a hack to get around the absurd habit of MS-DOS editors
  73. % of adding an EOF character at the end of the file.
  74. <1a> cvn { } def
  75.  
  76. % Acquire the debugging flags.
  77. currentdict /DEBUG known   /DEBUG exch def
  78.   /VMDEBUG
  79.     DEBUG {{print mark
  80.             systemdict /level2dict known
  81.          { .currentglobal dup false .setglobal vmstatus
  82.            true .setglobal vmstatus 3 -1 roll pop
  83.            6 -2 roll pop .setglobal
  84.          }
  85.          { vmstatus 3 -1 roll pop
  86.          }
  87.         ifelse usertime 16#fffff and counttomark
  88.           { ( ) print (           ) cvs print }
  89.         repeat pop
  90.         ( ) print systemdict length (    ) cvs print
  91.         ( ) print countdictstack (  ) cvs print
  92.         ( <) print count (  ) cvs print (>\n) print flush
  93.       }}
  94.       {{pop
  95.       }}
  96.      ifelse
  97.   def
  98.  
  99. currentdict /DELAYBIND known   /DELAYBIND exch def
  100. currentdict /DISKFONTS known   /DISKFONTS exch def
  101. currentdict /ESTACKPRINT known   /ESTACKPRINT exch def
  102. currentdict /FAKEFONTS known   /FAKEFONTS exch def
  103. currentdict /FIXEDMEDIA known   /FIXEDMEDIA exch def
  104. currentdict /FIXEDRESOLUTION known   /FIXEDRESOLUTION exch def
  105. currentdict /LOCALFONTS known   /LOCALFONTS exch def
  106. currentdict /NOBIND known   /NOBIND exch def
  107. /.bind /bind load def
  108. NOBIND { /bind { } def } if
  109. currentdict /NOCACHE known   /NOCACHE exch def
  110. currentdict /NOCIE known   /NOCIE exch def
  111. currentdict /NODISPLAY known   not /DISPLAYING exch def
  112. currentdict /NOFONTMAP known   /NOFONTMAP exch def
  113. currentdict /NOFONTPATH known   /NOFONTPATH exch def
  114. currentdict /NOGC known   /NOGC exch def
  115. currentdict /NOPAUSE known   /NOPAUSE exch def
  116. currentdict /NOPLATFONTS known   /NOPLATFONTS exch def
  117. currentdict /NOPROMPT known   /NOPROMPT exch def
  118. % The default value of ORIENT1 is true, not false.
  119. currentdict /ORIENT1 known not { /ORIENT1 true def } if
  120. currentdict /OSTACKPRINT known   /OSTACKPRINT exch def
  121. currentdict /OUTPUTFILE known    % obsolete
  122.  { /OutputFile /OUTPUTFILE load def
  123.    currentdict /OUTPUTFILE .undef
  124.  } if
  125. currentdict /QUIET known   /QUIET exch def
  126. currentdict /SAFER known   /SAFER exch def
  127. currentdict /SHORTERRORS known   /SHORTERRORS exch def
  128. currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  129.  
  130. % Acquire environment variables.
  131. currentdict /DEVICE known not
  132.  { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  133.  
  134. (START) VMDEBUG
  135.  
  136. % Open the standard files, so they will be open at the outermost save level.
  137. (%stdin) (r) file pop
  138. (%stdout) (w) file pop
  139. (%stderr) (w) file pop
  140.  
  141. % Define a procedure for skipping over an unneeded section of code.
  142. % This avoids allocating space for the skipped procedures.
  143. % We can't use readline, because that imposes a line length limit.
  144. /.skipeof    % <string> .skipeof -
  145.  { currentfile exch 1 exch .subfiledecode flushfile
  146.  } bind def
  147.  
  148. % If we're delaying binding, remember everything that needs to be bound later.
  149. DELAYBIND NOBIND not and
  150.  { .currentglobal false .setglobal
  151.    userdict /.delaybind 1500 array put
  152.    .setglobal
  153.    userdict /.delaycount 0 put
  154.     % When we've done the delayed bind, we want to stop saving.
  155.     % Detect this by the disappearance of .delaybind.
  156.    /bind
  157.     { userdict /.delaybind .knownget
  158.        { .delaycount 2 index put
  159.          userdict /.delaycount .delaycount 1 add put
  160.        }
  161.        { .bind
  162.        }
  163.       ifelse
  164.     } bind def
  165.  } if
  166.  
  167. % Define procedures to assist users who don't read the documentation.
  168. userdict begin
  169. /help
  170.  { (Enter PostScript commands.  '(filename) run' runs a file, 'quit' exits.\n)
  171.    print flush
  172.  } bind def
  173. /? /help load def
  174. end
  175.  
  176. % Define =string, which is used by some PostScript programs even though
  177. % it isn't documented anywhere.
  178. % Put it in userdict so that each context can have its own copy.
  179. userdict /=string 256 string put
  180.  
  181. % Print the greeting.
  182.  
  183. /printgreeting
  184.  { mark
  185.    product (Ghostscript) search
  186.     { pop pop pop
  187.       (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)
  188.     }
  189.     { pop
  190.     }
  191.    ifelse
  192.    (\n) copyright
  193.    (\)\n) revisiondate 100 mod (-)
  194.    revisiondate 100 idiv 100 mod (-)
  195.    revisiondate 10000 idiv ( \()
  196.    revision 10 mod
  197.    revision 10 idiv 10 mod (.)
  198.    revision 100 idiv ( )
  199.    product
  200.    counttomark
  201.     { (%stdout) (w) file exch false .writecvp
  202.     } repeat pop
  203.  } bind def
  204.  
  205. QUIET not { printgreeting flush } if
  206.  
  207. % Define a special version of def for making operator procedures.
  208. /odef        % <name> <proc> odef -
  209.  { 1 index exch .makeoperator def
  210.  } .bind def
  211.  
  212. %**************** BACKWARD COMPATIBILITY
  213. /getdeviceprops
  214.  { null .getdeviceparams
  215.  } bind odef
  216. /.putdeviceprops
  217.  { null true counttomark 1 add 3 roll .putdeviceparams
  218.    dup type /booleantype ne
  219.     { dup mark eq { /unknown /rangecheck } if
  220.       counttomark 4 add 1 roll cleartomark pop pop pop
  221.       /.putdeviceprops load exch signalerror
  222.     }
  223.    if
  224.  } bind odef
  225. /.devicenamedict 1 dict dup /OutputDevice dup put def
  226. /.devicename
  227.  { //.devicenamedict .getdeviceparams exch pop exch pop
  228.  } bind odef
  229. /max { .max } bind def
  230. /min { .min } bind def
  231. /.currentfilladjust { .currentfilladjust2 pop } bind odef
  232. /.setfilladjust { dup .setfilladjust2 } bind odef
  233. /.writecvs { false .writecvp } bind odef
  234.  
  235. % Define predefined procedures substituting for operators,
  236. % in alphabetical order.
  237.  
  238. userdict /#copies 1 put
  239. % Adobe implementations don't accept /[ or /], so we don't either.
  240. ([) cvn
  241.     /mark load def
  242. (]) cvn
  243.     {counttomark array astore exch pop} odef
  244. /abs    {dup 0 lt {neg} if} odef
  245. % .beginpage is an operator in Level 2.
  246. /.beginpage { } odef
  247. /copypage
  248.     { 1 .endpage
  249.        { .currentnumcopies false .outputpage
  250.          (>>copypage, press <return> to continue<<\n) .confirm
  251.        }
  252.       if .beginpage
  253.     } odef
  254. % .currentnumcopies is redefined in Level 2.
  255. /.currentnumcopies { #copies } odef
  256. /setcolorscreen where { pop        % not in all Level 1 configurations
  257.    /currentcolorscreen
  258.     { .currenthalftone
  259.        { { 60 exch 0 exch 3 copy 6 copy }    % halftone - not possible
  260.          { 3 copy 6 copy }            % screen
  261.          { }                % colorscreen
  262.        }
  263.       exch get exec
  264.     } odef
  265. } if
  266. /currentscreen
  267.     { .currenthalftone
  268.        { { 60 exch 0 exch }            % halftone - not possible
  269.          { }                % screen
  270.          { 12 3 roll 9 { pop } repeat }    % colorscreen
  271.        }
  272.       exch get exec
  273.     } odef
  274. /.echo /echo load def
  275. userdict /.echo.mode true put
  276. /echo    {dup /.echo.mode exch store .echo} odef
  277. /eexec
  278.     { 55665 //filterdict /eexecDecode get exec
  279.       cvx //systemdict begin stopped
  280.         % Only pop systemdict if it is still the top element,
  281.         % because this is apparently what Adobe interpreters do.
  282.       currentdict //systemdict eq { end } if
  283.       { stop } if
  284.     } odef
  285. % .endpage is an operator in Level 2.
  286. /.endpage { 2 ne } odef
  287. % erasepage mustn't use gsave/grestore, because we call it before
  288. % the graphics state stack has been fully initialized.
  289. /erasepage
  290.     { /currentcolor where
  291.        { pop currentcolor currentcolorspace { setcolorspace setcolor } }
  292.        { /currentcmykcolor where
  293.           { pop currentcmykcolor { setcmykcolor } }
  294.           { currentrgbcolor { setrgbcolor } }
  295.          ifelse
  296.        }
  297.       ifelse 1 setgray .fillpage exec
  298.     } odef
  299. /executive
  300.     { { prompt
  301.          { (%statementedit) (r) file } stopped
  302.          { pop pop $error /errorname get /undefinedfilename eq
  303.         { .clearerror exit } if        % EOF
  304.            handleerror null        % ioerror??
  305.          }
  306.         if
  307.         cvx execute
  308.       } loop
  309.     } odef
  310. /filter
  311.     { //filterdict 1 index .knownget
  312.        { exch pop exec }
  313.        { /filter load /undefined signalerror }
  314.       ifelse
  315.     } odef
  316. /handleerror
  317.     { errordict /handleerror get exec } bind def
  318. /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
  319. /identmatrix
  320.     { //identmatrix exch copy } odef
  321. /initgraphics
  322.     { initmatrix newpath initclip
  323.       1 setlinewidth 0 setlinecap 0 setlinejoin
  324.       [] 0 setdash 0 setgray 10 setmiterlimit
  325.     } odef
  326. /languagelevel 1 def        % gs_lev2.ps may change this
  327. /makeimagedevice { false makewordimagedevice } odef
  328. /matrix    { 6 array identmatrix } odef
  329. /pathbbox { false .pathbbox } odef
  330. /prompt    { flush flushpage
  331.       (GS) print
  332.       count 0 ne { (<) print count =only } if
  333.       (>) print flush
  334.     } bind def
  335. /pstack    { 0 1 count 3 sub { index == } for } bind def
  336. /putdeviceprops
  337.     { .putdeviceprops { erasepage } if } odef
  338. /quit    { /quit load 0 .quit } odef
  339. /run    { dup type /filetype ne { (r) file } if
  340.         % We must close the file when execution terminates,
  341.         % regardless of the state of the stack,
  342.         % and then propagate an error, if any.
  343.       cvx .runexec
  344.     } odef
  345. /setdevice
  346.     { .setdevice { erasepage } if } odef
  347. /showpage
  348.     { 0 .endpage
  349.        { .currentnumcopies true .outputpage
  350.          (>>showpage, press <return> to continue<<\n) .confirm
  351.          erasepage
  352.        }
  353.       if initgraphics .beginpage
  354.     } odef
  355. % Code output by Adobe Illustrator relies on the fact that
  356. % `stack' is a procedure, not an operator!!!
  357. /stack    { 0 1 count 3 sub { index = } for } bind def
  358. /start    { executive } def
  359. /stop    { true .stop } odef
  360. % Internal uses of stopped that aren't going to do a stop if an error occurs
  361. % should use .internalstopped to avoid setting newerror et al.
  362. /stopped { false .stopped } odef
  363. /.internalstopped { null .stopped null ne } bind def
  364. /store    { 1 index where { 3 1 roll put } { def } ifelse } odef
  365. % When running in Level 1 mode, this interpreter is supposed to be
  366. % compatible with PostScript "version" 54.0 (I think).
  367. /version (54.0) def
  368.  
  369. % internaldict is defined in systemdict, but is allocated in local VM.
  370. systemdict /internaldict .knownget not { 0 } if type /operatortype ne
  371.  { .currentglobal false .setglobal
  372.    //systemdict /internaldict known not { /internaldict 5 dict def } if
  373.    /internaldict
  374.     [ /dup load 1183615869 /eq load
  375.        [ /pop load internaldict ] cvx
  376.        [ /internaldict /cvx load /invalidaccess /signalerror cvx ] cvx
  377.       /ifelse load
  378.     ] cvx bind odef
  379.    .setglobal
  380.  } if
  381.  
  382. % Define some additional built-in procedures (beyond the ones defined by
  383. % the PostScript Language Reference Manual).
  384. % Warning: these are not guaranteed to stay the same from one release
  385. % to the next!
  386. /concatstrings
  387.     { exch dup length 2 index length add string    % str2 str1 new
  388.       dup dup 4 2 roll copy        % str2 new new new1
  389.       length 4 -1 roll putinterval
  390.     } bind def
  391. /copyarray
  392.     { dup length array copy } bind def
  393. % Copy a dictionary per the Level 2 spec even in Level 1.
  394. /.copydict        % <fromdict> <todict> .copydict <todict>
  395.     { dup 3 -1 roll { put dup } forall pop } bind def
  396. /copystring
  397.     { dup length string copy } bind def
  398. /finddevice
  399.     { //systemdict /devicedict get exch get
  400.       dup 1 get null eq
  401.        {        % This is the first request for this type of device.
  402.             % Create a default instance now.
  403.             % Stack: [proto null]
  404.          .currentglobal true .setglobal exch
  405.          dup dup 0 get copydevice 1 exch put
  406.          exch .setglobal
  407.        }
  408.       if 1 get
  409.     } bind def
  410. /.growdictlength    % get size for growing a dictionary
  411.     { length 3 mul 2 idiv 1 add
  412.     } bind def
  413. /.growdict        % grow a dictionary
  414.     { dup .growdictlength .setmaxlength
  415.     } bind def
  416. /.growput        % put, grow the dictionary if needed
  417.     { 2 index length 3 index maxlength eq
  418.        { 3 copy pop known not { 2 index .growdict } if
  419.        } if
  420.       put
  421.     } bind def
  422. /.packtomark
  423.     { counttomark packedarray exch pop } bind def
  424. /ppstack
  425.     { 0 1 count 3 sub { index === } for } bind def
  426. /runlibfile
  427.     { findlibfile
  428.        { exch pop run }
  429.        { /undefinedfilename signalerror }
  430.       ifelse
  431.     } bind def
  432. /selectdevice
  433.     { finddevice setdevice .setdefaultscreen } bind def
  434. /signalerror        % <object> <errorname> signalerror -
  435.     { errordict exch get exec } bind def
  436.  
  437. % Define the =[only] procedures.  Also define =print,
  438. % which is used by some PostScript programs even though
  439. % it isn't documented anywhere.
  440. /write=only
  441.     { { .writecvs } .internalstopped
  442.        { pop (--nostringval--) writestring
  443.        }
  444.       if
  445.     } bind def
  446. /write=
  447.     { 1 index exch write=only (\n) writestring
  448.     } bind def
  449. /=only    { (%stdout) (w) file exch write=only } bind def
  450. /=    { =only (\n) print } bind def
  451. /=print    /=only load def
  452. % Temporarily define == as = for the sake of runlibfile0.
  453. /== /= load def
  454.  
  455. % Define procedures for getting and setting the current device resolution.
  456.  
  457. /gsgetdeviceprop    % <device> <propname> gsgetdeviceprop <value>
  458.  { 2 copy mark exch null .dicttomark .getdeviceparams
  459.    dup mark eq        % if true, not found
  460.     { pop dup /undefined signalerror }
  461.     { 5 1 roll pop pop pop pop }
  462.    ifelse
  463.  } bind def
  464. /gscurrentresolution    % - gscurrentresolution <[xres yres]>
  465.  { currentdevice /HWResolution gsgetdeviceprop
  466.  } bind def
  467. /gssetresolution    % <[xres yres]> gssetresolution -
  468.  { 2 array astore mark exch /HWResolution exch
  469.    currentdevice copydevice putdeviceprops setdevice
  470.  } bind def
  471.  
  472. % Define auxiliary procedures needed for the above.
  473. /shellarguments        % -> shell_arguments true (or) false
  474.     { /ARGUMENTS where
  475.        { /ARGUMENTS get dup type /arraytype eq
  476.           { aload pop /ARGUMENTS null store true }
  477.           { pop false }
  478.          ifelse }
  479.        { false } ifelse
  480.     } bind def
  481. /.confirm
  482.     { DISPLAYING NOPAUSE not and
  483.        {    % Print a message (unless NOPROMPT is true)
  484.         % and wait for the user to type something.
  485.         % If the user just types a newline, flush it.
  486.          NOPROMPT { pop } { print flush } ifelse
  487.          .echo.mode false echo
  488.          (%stdin) (r) file dup read
  489.           { dup (\n) 0 get eq { pop pop } { unread } ifelse }
  490.           { pop }
  491.          ifelse echo
  492.        }
  493.        { pop
  494.        }
  495.       ifelse
  496.     } bind def
  497.  
  498. % Define the procedure used by .runfile, .runstdin and .runstring
  499. % for executing user input.
  500. % This is called with a procedure or executable file on the operand stack.
  501. /execute
  502.     { stopped
  503.       $error /newerror get and
  504.        { handleerror flush
  505.        } if
  506.     } odef
  507. % Define an execute analogue of runlibfile0.
  508. /execute0
  509.     { stopped
  510.       $error /newerror get and
  511.        { handleerror flush /execute0 cvx 1 .quit
  512.        } if
  513.     } bind def
  514. % Define the procedure that the C code uses for running files
  515. % named on the command line.
  516. /.runfile { { runlibfile } execute } def
  517. % Define the procedure that the C code uses for running piped input.
  518. /.runstdin { (%stdin) (r) file cvx execute0 } bind def
  519. % Define the procedure that the C code uses for running commands
  520. % given on the command line with -c.
  521. /.runstring { cvx execute } def
  522.  
  523. % Define a special version of runlibfile that aborts on errors.
  524. /runlibfile0
  525.     { cvlit dup /.currentfilename exch def
  526.        { findlibfile not { stop } if }
  527.       stopped
  528.        { (Can't find \(or open\) initialization file ) print
  529.          .currentfilename == flush /runlibfile0 cvx 1 .quit
  530.        } if
  531.       exch pop cvx stopped
  532.        { (While reading ) print .currentfilename print (:\n) print flush
  533.          handleerror /runlibfile0 1 .quit
  534.        } if
  535.     } bind def
  536. % Temporarily substitute it for the real runlibfile.
  537. /.runlibfile /runlibfile load def
  538. /runlibfile /runlibfile0 load def
  539.  
  540. % Create the error handling machinery.
  541. % Define the standard error handlers.
  542. % The interpreter has created the ErrorNames array.
  543. /.unstoppederrorhandler    % <command> <errorname> .unstoppederrorhandler -
  544.  {    % This is the handler that gets used for recursive errors,
  545.     % or errors outside the scope of a 'stopped'.
  546.    2 copy SHORTERRORS
  547.     { (%%[ Error: ) print =only flush
  548.       (; OffendingCommand: ) print =only ( ]%%\n) print
  549.     }
  550.     { (Unrecoverable error: ) print =only flush
  551.       ( in ) print = flush
  552.       count 2 gt
  553.        { (Operand stack:\n  ) print
  554.      2 1 count 3 sub { (  ) print index =only flush } for
  555.      (\n) print flush
  556.        } if
  557.     }
  558.    ifelse
  559.    -1 0 1 //ErrorNames length 1 sub
  560.     { dup //ErrorNames exch get 3 index eq
  561.        { not exch pop exit } { pop } ifelse
  562.     }
  563.    for exch pop .quit
  564.  } bind def
  565. /.errorhandler        % <command> <errorname> .errorhandler -
  566.   {        % Detect an internal 'stopped'.
  567.     .instopped { null eq { pop pop stop } if } if
  568.     $error /.inerror get .instopped { pop } { pop true } ifelse
  569.      { .unstoppederrorhandler
  570.      } if    % detect error recursion
  571.     $error /globalmode .currentglobal false .setglobal put
  572.     $error /.inerror true put
  573.     $error /newerror true put
  574.     $error exch /errorname exch put
  575.     $error exch /command exch put
  576.     $error /recordstacks get $error /errorname get /VMerror ne and
  577.      {        % Attempt to store the stack contents atomically.
  578.        count array astore dup $error /ostack 4 -1 roll
  579.        countexecstack array execstack $error /estack 3 -1 roll
  580.        countdictstack array dictstack $error /dstack 3 -1 roll
  581.        put put put aload pop
  582.      }
  583.      { $error /dstack .undef
  584.        $error /estack .undef
  585.        $error /ostack .undef
  586.      }
  587.     ifelse
  588.     $error /position currentfile status
  589.      { currentfile { fileposition } .internalstopped { pop null } if
  590.      }
  591.      {        % If this was a scanner error, the file is no longer current,
  592.         % but the command holds the file, which may still be open.
  593.        $error /command get dup type /filetype eq
  594.         { { fileposition } .internalstopped { pop null } if }
  595.         { pop null }
  596.        ifelse
  597.      }
  598.     ifelse put
  599.         % During initialization, we don't reset the allocation
  600.         % mode on errors.
  601.     $error /globalmode get $error /.nosetlocal get and .setglobal
  602.     $error /.inerror false put
  603.     stop
  604.   } bind def
  605. % Define the standard handleerror.  We break out the printing procedure
  606. % (.printerror) so that it can be extended for binary output
  607. % if the Level 2 facilities are present.
  608.   /.printerror
  609.    { $error begin
  610.        /command load errorname SHORTERRORS
  611.     { (%%[ Error: ) print =only flush
  612.       (; OffendingCommand: ) print =only
  613.       currentdict /errorinfo .knownget
  614.        { (;\nErrorInfo:) print
  615.          dup type /arraytype eq
  616.           { { ( ) print =only } forall }
  617.           { ( ) print =only }
  618.          ifelse
  619.        } if
  620.           ( ]%%\n) print flush
  621.     }
  622.     { (Error: ) print ==only flush
  623.       ( in ) print ==only flush
  624.       currentdict /errorinfo .knownget
  625.        { (\nAdditional information: ) print ==only flush
  626.        } if
  627.       .printerror_long
  628.     }
  629.        ifelse
  630.        .clearerror
  631.      end
  632.      flush
  633.     } bind def     
  634.   /.printerror_long            % long error printout,
  635.                     % $error is on the dict stack
  636.    {    % Push the (anonymous) stack printing procedure.
  637.     %  <heading> <==flag> <override-name> <stackname> proc
  638.        {
  639.      currentdict exch .knownget    % stackname defined in $error?
  640.      {
  641.        4 1 roll            % stack: <stack> <head> <==flag> <over>
  642.        errordict exch .knownget    % overridename defined?
  643.        { 
  644.          exch pop exch pop exec    % call override with <stack>
  645.        }
  646.        { 
  647.          exch print exch        % print heading. stack <==flag> <stack>
  648.          1 index not { (\n) print } if
  649.          { 1 index { (\n    ) } { (   ) } ifelse print
  650.            dup type /dicttype eq
  651.            {
  652.          (--dict:) print
  653.          dup rcheck
  654.           { dup length =only (/) print maxlength =only }
  655.           { pop }
  656.          ifelse
  657.          (--) print
  658.            }
  659.            {
  660.          dup type /stringtype eq 2 index or
  661.          { ===only } { =only } ifelse
  662.            } ifelse
  663.          } forall
  664.          pop
  665.        }
  666.        ifelse            % overridden
  667.      }
  668.      { pop pop pop
  669.      }
  670.      ifelse                % stack known
  671.        }
  672.  
  673.        (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
  674.        (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
  675.        (\nBacktrace:) true /.printbacktrace /backtrace 4 index exec
  676.        (\nDictionary stack:) false /.printdstack /dstack 4 index exec
  677.        (\n) print
  678.        pop    % printing procedure
  679.  
  680.        errorname /VMerror eq
  681.     { (VM status:) print mark vmstatus
  682.       counttomark { ( ) print counttomark -1 roll dup =only } repeat
  683.       cleartomark (\n) print
  684.     } if
  685.  
  686.        .languagelevel 2 ge
  687.     { (Current allocation mode is ) print
  688.       globalmode { (global\n) } { (local\n) } ifelse print
  689.     } if
  690.  
  691.        .oserrno dup 0 ne
  692.     { (Last OS error: ) print
  693.       errorname /VMerror ne
  694.        { dup .oserrorstring { = pop } { = } ifelse }
  695.        { = }
  696.       ifelse
  697.     }
  698.     { pop
  699.     }
  700.        ifelse
  701.  
  702.        position null ne
  703.     { (Current file position is ) print position = }
  704.        if
  705.  
  706.    } bind def
  707. % Define a procedure for clearing the error indication.
  708. /.clearerror
  709.  { $error /newerror false put
  710.    $error /errorinfo .undef
  711.    0 .setoserrno
  712.  } bind def
  713.  
  714. % Define $error.  This must be in local VM.
  715. .currentglobal false .setglobal
  716. /$error 40 dict def        % newerror, errorname, command, errorinfo,
  717.                 % ostack, estack, dstack, recordstacks,
  718.                 % binary, globalmode,
  719.                 % .inerror, .nosetlocal, position,
  720.         % plus extra space for badly designed error handers.
  721. $error begin
  722.   /newerror false def
  723.   /recordstacks true def
  724.   /binary false def
  725.   /globalmode .currentglobal def
  726.   /.inerror false def
  727.   /.nosetlocal true def
  728.   /position null def
  729. end
  730. % Define errordict similarly.  It has one entry per error name,
  731. %   plus handleerror.
  732. /errordict ErrorNames length 1 add dict def
  733. .setglobal        % contents of errordict are global
  734. errordict begin
  735.   ErrorNames
  736.    { mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx def
  737.    } forall
  738. % The handlers for interrupt and timeout are special; there is no
  739. % 'current object', so they push their own name.
  740.    { /interrupt /timeout }
  741.    { mark 1 index dup systemdict /.errorhandler get /exec load .packtomark cvx def
  742.    } forall
  743. /handleerror
  744.  { //systemdict /.printerror get exec
  745.  } bind def
  746. end
  747.  
  748. % Define the [write]==[only] procedures.
  749. /.dict 26 dict dup
  750. begin def
  751.   /.cvp {1 index exch .writecvs} bind def
  752.   /.nop {exch pop .p} bind def
  753.   /.p {1 index exch writestring} bind def
  754.   /.p1 {2 index exch writestring} bind def
  755.   /.p2 {3 index exch writestring} bind def
  756.   /.print
  757.     { dup type .dict exch .knownget
  758.        { dup type /stringtype eq { .nop } { exec } ifelse }
  759.        { (-) .p1 type .cvp (-) .p }
  760.       ifelse
  761.     } bind def
  762.   /.pstring
  763.     {  { dup dup 32 lt exch 127 ge or
  764.           { (\\) .p1 2 copy -6 bitshift 48 add write
  765.         2 copy -3 bitshift 7 and 48 add write
  766.         7 and 48 add
  767.           }
  768.           { dup dup -2 and 40 eq exch 92 eq or {(\\) .p1} if
  769.           }
  770.          ifelse 1 index exch write
  771.        }
  772.       forall
  773.     } bind def  
  774.   /booleantype /.cvp load def
  775.   /conditiontype (-condition-) def
  776.   /devicetype (-device-) def
  777.   /dicttype (-dict-) def
  778.   /filetype (-file-) def
  779.   /fonttype (-fontID-) def
  780.   /gstatetype (-gstate-) def
  781.   /integertype /.cvp load def
  782.   /locktype (-lock-) def
  783.   /marktype (-mark-) def
  784.   /nulltype (null) def
  785.   /realtype {1 index exch true .writecvp} bind def
  786.   /savetype (-save-) def
  787.   /nametype
  788.     {dup xcheck not {(/) .p1} if
  789.      1 index exch .writecvs} bind def
  790.   /arraytype
  791.     {dup rcheck
  792.       {() exch dup xcheck
  793.         {({) .p2
  794.          {exch .p1
  795.           1 index exch .print pop ( )} forall
  796.          (})}
  797.         {([) .p2
  798.          {exch .p1
  799.           1 index exch .print pop ( )} forall
  800.          (])}
  801.        ifelse exch pop .p}
  802.       {(-array-) .nop}
  803.      ifelse} bind def
  804.   /operatortype
  805.       {(--) .p1 .cvp (--) .p} bind def
  806.   /packedarraytype
  807.     { dup rcheck
  808.        { arraytype }
  809.        { (-packedarray-) .nop }
  810.       ifelse
  811.     } bind def
  812.   /stringtype
  813.     { dup rcheck
  814.        { (\() .p1 dup length 200 le
  815.           { .pstring }
  816.           { 0 200 getinterval .pstring (...) .p }
  817.          ifelse (\)) .p
  818.        }
  819.        { (-string-) .nop
  820.        }
  821.       ifelse
  822.     } bind def
  823. {//.dict begin .print pop end}
  824.   bind
  825. end
  826.  
  827. /write==only exch def
  828. /write== {1 index exch write==only (\n) writestring} bind def
  829. /==only { (%stdout) (w) file exch write==only } bind def
  830. /== {==only (\n) print} bind def
  831.  
  832. % Define [write]===[only], an extension that prints dictionaries
  833. % in readable form and doesn't truncate strings.
  834. /.dict /write==only load 0 get dup length dict .copydict dup
  835. begin def
  836.   /dicttype
  837.     { dup rcheck
  838.        { (<< ) .p1
  839.           { 2 index 3 -1 roll .print pop ( ) .p1
  840.         1 index exch .print pop ( ) .p
  841.           }
  842.          forall (>>) .p
  843.        }
  844.        { (-dict-) .nop
  845.        }
  846.       ifelse
  847.     } bind def
  848.   /stringtype
  849.     { dup rcheck
  850.        { (\() .p1 .pstring (\)) .p }
  851.        { (-string-) .nop }
  852.       ifelse
  853.     } bind def
  854.  
  855. {//.dict begin .print pop end}
  856.   bind
  857. end
  858.  
  859. /write===only exch def
  860. /write=== {1 index exch write===only (\n) writestring} bind def
  861. /===only { (%stdout) (w) file exch write===only } bind def
  862. /=== { ===only (\n) print } bind def
  863.  
  864. (END PROCS) VMDEBUG
  865.  
  866. % Define the font directory.
  867. /FontDirectory false .setglobal 100 dict true .setglobal def
  868.  
  869. % Define the encoding dictionary.
  870. /EncodingDirectory 10 dict def    % enough for Level 2 + PDF standard encodings
  871.  
  872. % Define .findencoding.  (This is redefined in Level 2.)
  873. /.findencoding
  874.  { //EncodingDirectory exch get exec
  875.  } bind def
  876. /.defineencoding
  877.  { //EncodingDirectory 3 1 roll put
  878.  } bind def
  879. % If we've got the composite font extensions, define findencoding.
  880. /rootfont where { pop /findencoding { .findencoding } odef } if
  881.  
  882. % Load StandardEncoding.
  883. %% Replace 1 (gs_std_e.ps)
  884. (gs_std_e.ps) dup runlibfile VMDEBUG
  885.  
  886. % Load ISOLatin1Encoding.
  887. %% Replace 1 (gs_iso_e.ps)
  888. (gs_iso_e.ps) dup runlibfile VMDEBUG
  889.  
  890. % Define stubs for the Symbol and Dingbats encodings.
  891. % Note that the first element of the procedure must be the file name,
  892. % since gs_lev2.ps extracts it to set up the Encoding resource category.
  893.  
  894.   /SymbolEncoding { /SymbolEncoding .findencoding } bind def
  895. %% Replace 3 (gs_sym_e.ps)
  896.   EncodingDirectory /SymbolEncoding
  897.    { (gs_sym_e.ps) //systemdict begin runlibfile SymbolEncoding end }
  898.   bind put
  899.  
  900.   /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
  901. %% Replace 3 (gs_dbt_e.ps)
  902.   EncodingDirectory /DingbatsEncoding
  903.    { (gs_dbt_e.ps) //systemdict begin runlibfile DingbatsEncoding end }
  904.   bind put
  905.  
  906. (END FONTDIR/ENCS) VMDEBUG
  907.  
  908. % Construct a dictionary of all available devices.
  909. % These are (read-only) device prototypes that can't be
  910. % installed or have their parameters changed.  For this reason,
  911. % the value in the dictionary is actually a 2-element writable array,
  912. % to allow us to create a default instance of the prototype on demand.
  913.  
  914.     % Loop until the .getdevice gets a rangecheck.
  915. errordict /rangecheck 2 copy get
  916. errordict /rangecheck { pop stop } put    % pop the command
  917.   0 { {dup .getdevice exch 1 add} loop} null .stopped pop
  918.   1 add dict  /devicedict 1 index def
  919.   begin            % 2nd copy of count is on stack
  920.    { dup .devicename exch
  921.      dup wcheck { dup } { null } ifelse 2 array astore def
  922.    } repeat
  923.   end
  924. put        % errordict /rangecheck
  925. .clearerror
  926. /devicenames devicedict { pop } forall devicedict length packedarray def
  927.  
  928. % Determine the default device.
  929. /defaultdevice DISPLAYING
  930.  { systemdict /DEVICE .knownget
  931.     { devicedict 1 index known not
  932.        { (Unknown device: ) print =
  933.      flush /defaultdevice cvx 1 .quit
  934.        }
  935.       if
  936.     }
  937.     { 0 .getdevice .devicename
  938.     }
  939.    ifelse
  940.  }
  941.  { /nullpage
  942.  }
  943. ifelse
  944. /.defaultdevicename 1 index def
  945. finddevice    % make a copy
  946. def
  947. devicedict /Default devicedict .defaultdevicename get put
  948.  
  949. (END DEVS) VMDEBUG
  950.  
  951. % Define statusdict, for the benefit of programs
  952. % that think they are running on a LaserWriter or similar printer.
  953. %% Replace 1 (gs_statd.ps)
  954. (gs_statd.ps) runlibfile
  955.  
  956. (END STATD) VMDEBUG
  957.  
  958. % Load the standard font environment.
  959. %% Replace 1 (gs_fonts.ps)
  960. (gs_fonts.ps) runlibfile
  961.  
  962. (END GS_FONTS) VMDEBUG
  963.  
  964. % Load the initialization files for optional features.
  965. %% Replace 4 INITFILES
  966. systemdict /INITFILES known
  967.  { INITFILES { dup runlibfile VMDEBUG } forall
  968.  }
  969. if
  970.  
  971. % If Level 2 functionality is implemented, enable it now.
  972. /.setlanguagelevel where
  973.  { pop 2 .setlanguagelevel
  974.  } if
  975.  
  976. (END INITFILES) VMDEBUG
  977.  
  978. % Create a null font.  This is the initial font.
  979. 8 dict dup begin
  980.   /FontMatrix [ 1 0 0 1 0 0 ] readonly def
  981.   /FontType 3 def
  982.   /FontName () def
  983.   /Encoding StandardEncoding def
  984.   /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
  985.   /BuildChar { pop pop 0 0 setcharwidth } bind def
  986.   /PaintType 0 def        % shouldn't be needed!
  987. end
  988. /NullFont exch definefont setfont
  989.  
  990. % Define NullFont as the font.
  991. /NullFont currentfont def
  992.  
  993. % Load initial fonts from FONTPATH directories, Fontmap file,
  994. % and/or .getccfont as appropriate.
  995. .loadinitialfonts
  996.  
  997. % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
  998. FontDirectory /NullFont .undef
  999.  
  1000. (END FONTS) VMDEBUG
  1001.  
  1002. % Restore the real definition of runlibfile.
  1003. /runlibfile /.runlibfile load def
  1004. currentdict /.runlibfile .undef
  1005.  
  1006. % Bind all the operators defined as procedures.
  1007. /.bindoperators        % binds operators in currentdict
  1008.  { % Temporarily disable the typecheck error.
  1009.    errordict /typecheck 2 copy get
  1010.    errordict /typecheck { pop } put    % pop the command
  1011.    currentdict
  1012.     { dup type /operatortype eq
  1013.        { % This might be a real operator, so bind might cause a typecheck,
  1014.      % but we've made the error a no-op temporarily.
  1015.      .bind        % do a real bind even if NOBIND is set
  1016.        }
  1017.       if pop pop
  1018.     } forall
  1019.    put
  1020.  } def
  1021. NOBIND DELAYBIND or not { .bindoperators } if
  1022.  
  1023. % Establish a default environment.
  1024.  
  1025. defaultdevice
  1026. DISPLAYING not { setdevice (%END DISPLAYING) .skipeof } if
  1027. systemdict /DEVICEWIDTH known
  1028. systemdict /DEVICEHEIGHT known or
  1029. systemdict /DEVICEWIDTHPOINTS known or
  1030. systemdict /DEVICEHEIGHTPOINTS known or
  1031. systemdict /DEVICEXRESOLUTION known or
  1032. systemdict /DEVICEYRESOLUTION known or
  1033. systemdict /PAPERSIZE known or
  1034. not { (%END DEVICE) .skipeof } if
  1035. % Let DEVICE{WIDTH,HEIGHT}[POINTS] override PAPERSIZE.
  1036. systemdict /PAPERSIZE known
  1037. systemdict /DEVICEWIDTH known not and
  1038. systemdict /DEVICEHEIGHT known not and
  1039. systemdict /DEVICEWIDTHPOINTS known not and
  1040. systemdict /DEVICEHEIGHTPOINTS known not and
  1041.  {    % Convert the paper size to device dimensions.
  1042.    true statusdict /.pagetypenames get
  1043.     { PAPERSIZE eq
  1044.        { PAPERSIZE load
  1045.          dup 0 get /DEVICEWIDTHPOINTS exch def
  1046.          1 get /DEVICEHEIGHTPOINTS exch def
  1047.          pop false exit
  1048.        }
  1049.       if
  1050.     }
  1051.    forall
  1052.     { (Unknown paper size: ) print PAPERSIZE ==only (.\n) print
  1053.     }
  1054.    if
  1055.  }
  1056. if
  1057. % Adjust the device parameters per the command line.
  1058. % It is possible to specify resolution, pixel size, and page size;
  1059. % since any two of these determine the third, conflicts are possible.
  1060. % We simply pass them to .setdeviceparams and let it sort things out.
  1061.    mark /HWResolution null /HWSize null /PageSize null .dicttomark
  1062.    .getdeviceparams .dicttomark begin
  1063.    mark
  1064.     % Check for resolution.
  1065.    /DEVICEXRESOLUTION where dup
  1066.     { exch pop HWResolution 0 DEVICEXRESOLUTION put }
  1067.    if
  1068.    /DEVICEYRESOLUTION where dup
  1069.     { exch pop HWResolution 1 DEVICEYRESOLUTION put }
  1070.    if
  1071.    or { /HWResolution HWResolution } if
  1072.     % Check for device sizes specified in pixels.
  1073.    /DEVICEWIDTH where dup
  1074.     { exch pop HWSize 0 DEVICEWIDTH put }
  1075.    if
  1076.    /DEVICEHEIGHT where dup
  1077.     { exch pop HWSize 1 DEVICEHEIGHT put }
  1078.    if
  1079.    or { /HWSize HWSize } if
  1080.     % Check for device sizes specified in points.
  1081.    /DEVICEWIDTHPOINTS where dup
  1082.     { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
  1083.    if
  1084.    /DEVICEHEIGHTPOINTS where dup
  1085.     { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
  1086.    if
  1087.    or { /PageSize PageSize } if
  1088.     % Check whether any parameters were set.
  1089.    dup mark eq { pop } { defaultdevice putdeviceprops } ifelse
  1090.    end
  1091. %END DEVICE
  1092. % Set any device properties defined on the command line.
  1093. % If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
  1094. systemdict /BufferSpace known
  1095. systemdict /MaxBitmap known not and
  1096.  { systemdict /MaxBitmap BufferSpace put
  1097.  } if
  1098. dup getdeviceprops
  1099. counttomark 2 idiv
  1100.  { systemdict 2 index known
  1101.     { pop dup load counttomark 2 roll }
  1102.     { pop pop }
  1103.    ifelse
  1104.  } repeat
  1105. counttomark dup 0 ne
  1106.  { 2 add -1 roll putdeviceprops }
  1107.  { pop pop }
  1108. ifelse
  1109. setdevice        % does an erasepage
  1110. % If the media size is fixed, update the current page device dictionary.
  1111. FIXEDMEDIA
  1112. dup { pop systemdict /.currentpagedevice known } if
  1113. dup { pop .currentpagedevice exch pop } if
  1114. not { (%END MEDIA) .skipeof } if
  1115. currentpagedevice dup length dict .copydict
  1116. dup /InputAttributes
  1117. 2 copy get dup length dict .copydict
  1118.     % Stack: <pagedevice> <pagedevice> /InputAttributes <inputattrs>
  1119. dup length dict .copydict dup
  1120. 0 2 copy get dup length dict .copydict
  1121.     % Stack: <pagedevice> <pagedevice> /InputAttributes
  1122.     %   <inputattrs> <inputattrs> 0 <attrs0>
  1123. dup /PageSize 7 index /PageSize get
  1124. put                % PageSize in 0
  1125. put                % 0 in InputAttributes
  1126. put                % InputAttributes in pagedevice
  1127. .setpagedevice        
  1128. %END MEDIA
  1129. %END DISPLAYING
  1130.  
  1131. (END DEVICE) VMDEBUG
  1132.  
  1133. % Establish a default upper limit in the character cache,
  1134. % namely, enough room for a 18-point character at the resolution
  1135. % of the default device, or for a character consuming 1% of the
  1136. % maximum cache size, whichever is larger.
  1137. mark
  1138.     % Compute limit based on character size.
  1139.   18 dup dtransform
  1140.   exch abs cvi 31 add 32 idiv 4 mul    % X raster
  1141.   exch abs cvi mul        % Y
  1142.     % Compute limit based on allocated space.
  1143.   cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
  1144.   .max dup 10 idiv exch
  1145. setcacheparams
  1146. % Conditionally disable the character cache.
  1147. NOCACHE { 0 setcachelimit } if
  1148.  
  1149. (END CONFIG) VMDEBUG
  1150.  
  1151. % Establish an appropriate halftone screen.
  1152. % We make this a procedure so we can call it again when switching devices.
  1153.  
  1154. % Use an ordered dither for low-resolution devices.
  1155. /.setloresscreen    % <dpi> .setloresscreen -
  1156.  {    % The following 'ordered dither' spot function was contributed by
  1157.     % Gregg Townsend.  Thanks, Gregg!
  1158.    16.001 div 0            % not 16: avoids rounding problems
  1159.     { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
  1160.     0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
  1161.     CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
  1162.     3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
  1163.     FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
  1164.     01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
  1165.     C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
  1166.     31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
  1167.     F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
  1168.     0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
  1169.     CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
  1170.     3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
  1171.     FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
  1172.     02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
  1173.     C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
  1174.     32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
  1175.     F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
  1176.      > exch get 256 div
  1177.     }
  1178.    bind
  1179.         % Use correct, per-plane screens for CMYK devices only.
  1180.    //systemdict /setcolorscreen known processcolors 4 eq and
  1181.     { 3 copy 6 copy setcolorscreen }
  1182.     { setscreen }
  1183.    ifelse
  1184.    0 array cvx settransfer    % Genoa CET won't accept a packed array!
  1185.    /setstrokeadjust where { pop true setstrokeadjust } if
  1186.  } bind def
  1187. % Use a 45-degree spot screen for high-resolution devices.
  1188. /.sethiresscreen    % <dpi> .sethiresscreen -
  1189.  {    % According to information published by Hewlett-Packard,
  1190.     % they use a 60 line screen on 300 DPI printers and
  1191.     % an 85 line screen on 600 DPI printers.
  1192.     % 46 was suggested as a good frequency value for printers
  1193.     % between 200 and 400 DPI, so we use it for lower resolutions.
  1194.    //systemdict /DITHERPPI known
  1195.     { DITHERPPI }
  1196.     { dup cvi 100 idiv 6 .min {null 46 46 60 60 60 85} exch get }
  1197.    ifelse
  1198.    1 index 4.01 div .min    % at least a 4x4 cell
  1199.    45
  1200.     % The following screen algorithm is used by permission of the author.
  1201.     { 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos 
  1202.       1 0.08 sub mul add 2 div % (C) 1989 Berthold K.P. Horn
  1203.     }
  1204.    bind
  1205.     % Determine whether we have lots of process colors.
  1206.     % If so, don't bother with color screening or gamma correction.
  1207.    currentdevice mark
  1208.      /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
  1209.    .dicttomark .getdeviceparams
  1210.    counttomark 2 idiv 1 sub { exch pop min } repeat
  1211.    exch pop exch pop 32 lt 5 1 roll
  1212.     % Stack: doscreen dpi freq angle proc
  1213.     % Ghostscript currently doesn't use correct, per-plane halftones
  1214.     % unless setcolorscreen has been executed.  Since these are
  1215.     % computationally much more expensive than binary halftones,
  1216.     % we check to make sure they are really warranted, i.e., we have
  1217.     % a high-resolution CMYK device (i.e., not a display) with
  1218.     % fewer than 5 bits per plane (i.e., not a true-color device).
  1219.    4 -1 roll 150 ge
  1220.     { /setcolorscreen where
  1221.        { pop //systemdict /COLORSCREEN known
  1222.       { COLORSCREEN }
  1223.       { 3 index }
  1224.      ifelse
  1225.      dup false ne
  1226.       { 4 1 roll 3 copy 6 copy 13 -1 roll
  1227.     % For really high-quality screening on printers, we need to
  1228.     % give each plane its own screen angle.  Unfortunately,
  1229.     % this currently has very large space and time costs.
  1230.         true eq        % true => different angles,
  1231.                 % 0 => same angles
  1232.          { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
  1233.          }
  1234.         if setcolorscreen
  1235.       }
  1236.       { pop setscreen    % false => single binary screen
  1237.       }
  1238.      ifelse
  1239.        }
  1240.        { setscreen        % setcolorscreen not known
  1241.        }
  1242.       ifelse
  1243.     }
  1244.     { setscreen            % not high resolution
  1245.     }
  1246.    ifelse
  1247.             % Stack: doscreen
  1248.     {    % Set the transfer function to lighten up the grays.
  1249.     % We correct at the high end so that very light grays
  1250.     % don't disappear completely if they darken <1 screen pixel.
  1251.     % Parameter values closer to 1 are better for devices with
  1252.     % less dot spreading; lower values are better with more spreading.
  1253.     % The value 0.8 is a compromise that will probably please no one!
  1254.       { 0.8 exp dup dup 0.9375 gt exch 0.999 lt and    % > 15/16
  1255.      { .currentscreenlevels 1 sub    % tweak to avoid boundary
  1256.        1 exch div 1 exch sub .min
  1257.      }
  1258.     if
  1259.       }
  1260.     }
  1261.     {    % Set the transfer function to the identity.
  1262.       0 array cvx        % Genoa CET won't accept a packed array!
  1263.     }
  1264.    ifelse settransfer
  1265.    /setstrokeadjust where { pop false setstrokeadjust } if
  1266.     % Increase fill adjustment so that we effectively use Adobe's
  1267.     % any-part-of-pixel rule.
  1268.    0.5 .setfilladjust
  1269.  } bind def
  1270. % Set the default screen based on the device resolution.
  1271. /.setdefaultscreen
  1272.  {    % Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
  1273.    72 72 matrix defaultmatrix dtransform abs exch abs .min
  1274.    dup 150 lt //systemdict /DITHERPPI known not and
  1275.     { .setloresscreen } { .sethiresscreen }
  1276.    ifelse
  1277.  } bind def
  1278. .setdefaultscreen
  1279. initgraphics
  1280. % The interpreter relies on there being at least 2 entries
  1281. % on the graphics stack.  Establish the second one now.
  1282. gsave
  1283.  
  1284. % Define some control sequences as no-ops.
  1285. % This is a hack to get around problems
  1286. % in some common PostScript-generating applications.
  1287. % Note that <04> and <1a> are self-delimiting characters, like [.
  1288. <04> cvn { } def        % Apple job separator
  1289. %<0404> cvn { } def        % two of the same
  1290. <1b> cvn { } def        % MS Windows LaserJet 4 prologue
  1291. %<041b> cvn { } def        % MS Windows LaserJet 4 epilogue
  1292. (\001M) cvn            % TBCP initiator
  1293.  { currentfile /TBCPDecode filter cvx exec
  1294.  } bind def
  1295. /@PJL                % H-P job control
  1296.  { currentfile //=string readline { pop } if
  1297.  } bind def
  1298.  
  1299. % If we want a "safer" system, disable some obvious ways to cause havoc.
  1300. SAFER not { (%END SAFER) .skipeof } if
  1301. /file
  1302.  { dup (r) eq 2 index (%pipe*) .stringmatch not and
  1303.     { file }
  1304.     { /invalidfileaccess signalerror }
  1305.    ifelse
  1306.  } .bind odef
  1307. /renamefile { /invalidfileaccess signalerror } odef
  1308. /deletefile { /invalidfileaccess signalerror } odef
  1309. /putdeviceprops
  1310.  { counttomark
  1311.    dup 2 mod 0 eq { pop /rangecheck signalerror } if
  1312.    3 2 3 2 roll
  1313.     { dup index /OutputFile eq  
  1314.        { -2 roll 
  1315.          dup () ne { /putdeviceprops load /invalidfileaccess signalerror } if
  1316.          3 -1 roll
  1317.        }
  1318.        { pop
  1319.        }
  1320.       ifelse
  1321.     } for
  1322.    putdeviceprops
  1323.  } .bind odef
  1324.  
  1325. %END SAFER
  1326.  
  1327. % If we delayed binding, make it possible to do it later.
  1328. /.bindnow
  1329.  { //systemdict begin .bindoperators end
  1330.    % Temporarily disable the typecheck error.
  1331.    errordict /typecheck 2 copy get
  1332.    errordict /typecheck { pop } put    % pop the command
  1333.    0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
  1334.    userdict /.delaybind .undef        % reclaim the space
  1335.    userdict /.delaycount .undef
  1336.    put
  1337.  } .bind def
  1338.  
  1339. % Turn off array packing, since some PostScript code assumes that
  1340. % procedures are writable.
  1341. false setpacking
  1342.  
  1343. % Close up systemdict.
  1344. currentdict /.forceput .undef        % remove temptation
  1345. currentdict /filterdict .undef        % bound in where needed
  1346. end
  1347. WRITESYSTEMDICT not { systemdict readonly pop } if
  1348.  
  1349. (END INIT) VMDEBUG
  1350.  
  1351. % Establish local VM as the default.
  1352. false /setglobal where { pop setglobal } { .setglobal } ifelse
  1353. $error /.nosetlocal false put
  1354.  
  1355. % Clean up VM, and enable GC.
  1356. /vmreclaim where
  1357.  { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
  1358.  } if
  1359.  
  1360. (END GC) VMDEBUG
  1361.  
  1362. % The interpreter will run the initial procedure (start).
  1363.